<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="renderer" content="webkit|ie-comp|ie-stand" />
		<meta name="wiewport" content="width=device-width, initial-scale=1.0, maxinum-scale=1.0, user-scaleable=no" />
		<title>个人设置</title>
		<script type="text/javascript" src="/js/userCommon.js"></script>
	</head>

	<body class="main_body">
		<!--头部nav-->
		<div class="navbar navbar-default">
			<div class="container">
				<ul class="nav text-center quick_enter">
					<li><img src="/img/logo_login_03.jpg" class="nav_img" /></li>
					<li class="quick_enterli m-l-md">
						<a href="/entry.html">首页 </a>
					</li>
					<li class="quick_enterli">
						<a href="/theme.html" class="">强链接企业</a>
					</li>
					<li class="quick_enterli">
						<a href="/partner.html" class="">战略合作伙伴</a>
					</li>
					<li class="quick_enterli">
						<a href="/data.html" class="">数据看板</a>
					</li>
					<li class="dropdown pull-right admin_info">
						<img src="/img/shejishi_07.jpg" class="img-photo" />
						<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
							<span id="user_span"></span> <span class="drop_caret"></span>
						</a>
						<ul class="dropdown-menu">
							<li>
								<a href="/usercenter/myAttention.html" ><i class="fa fa-user-secret"></i> 个人中心</a>
							</li>
							<li class="hidden" id="backPageEnter">
								<a href="javascript:void(0)" ><i class="fa fa-server"></i> 后台管理</a>
							</li>
							<li>
								<a href="javascript:void(0)" id="logout_a"><i class="fa fa-sign-out"></i> 退出登录</a>
							</li>
						</ul>
					</li>
				</ul>
			</div>
		</div>
		<!--主体-->
		<div class="container containerbox">
			<!--左边导航-->
			<div class="left_side">
				<div class="ibox">
					<h3 class="topTitle">个人中心</h3>
					<ul class="leftMeun">
						<li>
							<a href="/usercenter/myAttention.html"><i class="fa fa-unlink" aria-hidden="true"></i> 我的关注</a>
						</li>
						<li>
							<a href="/usercenter/businessManage.html"><i class="fa fa-weixin" aria-hidden="true"></i> 企业管理</a>
						</li>
						<li class="">
							<a href="/usercenter/partnerManage.html"><i class="fa fa-user-times" aria-hidden="true"></i>合作伙伴管理</a>
						</li>
						<li>
							<a href="/usercenter/businessInfoManage.html"><i class="fa fa-wrench" aria-hidden="true"></i> 链接互动管理</a>
						</li>
						<li>
							<a href="/usercenter/needManage.html"><i class="fa fa-wrench" aria-hidden="true"></i> 企业需求管理</a>
						</li>
						<!-- <li>
							<a href="/usercenter/partnerManage.html"><i class="fa fa-user-times" aria-hidden="true"></i>合作伙伴管理</a>
						</li> -->
						<li  class="active">
							<a href="/usercenter/personalSettings.html"><i class="fa fa-user-times" aria-hidden="true"></i>个人设置</a>
						</li>
					</ul>
				</div>

			</div>
			<!--右边-->
			<div class="right_side">
				<div class="ibox">
					<div class="ibox-content" >
						<!--个人设置-->
						<div class="personOrg">
							<div class="titleDiv">
								<b class="blockB"></b> 个人设置
							</div>
							<form action="" class="m-t-lg" id="list">
								<div class="form-group clear">
									<label for="" class="control-label col-sm-1">姓名</label>
									<div class="col-sm-6 inpuDiv">
										<input type="text" id="realname" readonly="readonly" class="form-control"/>
									</div>
									<div class="col-xs-4">
										<a href="javascript:void(0);" onclick="showSave(this);" class="editBtn">修改</a>
										<button type="button" class="btn btn-sm btn-outline btn-success hidden" onclick="saveName(this,'realname')">保存</button>
										<button type="button" class="btn btn-sm btn-outline btn-default hidden" onclick="hideBtns(this);">取消</button>
									</div>
								</div>
								<div class="form-group clear">
									<label for="" class="control-label col-sm-1">账号</label>
									<div class="col-sm-6 inpuDiv">
										<input type="text" id="username" readonly="readonly" class="form-control"/>
									</div>
								</div>
								<div class="form-group clear">
									<label for="" class="control-label col-sm-1">单位</label>
									<div class="col-sm-6 inpuDiv">
										<input type="text" id="unit" class="form-control" readonly="readonly"/>
									</div>
									<div class="col-xs-4">
										<a href="javascript:void(0);" onclick="showSave(this);" class="editBtn">修改</a>
										<button type="button" class="btn btn-sm btn-outline btn-success hidden" onclick="saveName(this,'unit')">保存</button>
										<button type="button" class="btn btn-sm btn-outline btn-default hidden" onclick="hideBtns(this);">取消</button>
									</div>
								</div>
								<div class="form-group clear">
									<label for="" class="control-label col-sm-1">职位</label>
									<div class="col-sm-6 inpuDiv">
										<input type="text" id="position" class="form-control" readonly="readonly"/>
									</div>
									<div class="col-xs-4">
										<a href="javascript:void(0);" onclick="showSave(this);" class="editBtn">修改</a>
										<button type="button" class="btn btn-sm btn-outline btn-success hidden" onclick="saveName(this,'position')">保存</button>
										<button type="button" class="btn btn-sm btn-outline btn-default hidden" onclick="hideBtns(this);">取消</button>
									</div>
								</div>
								<div class="form-group clear">
									<label for="" class="control-label col-sm-1">手机号</label>
									<div class="col-sm-6 inpuDiv">
										<input type="text" id="mobile" class="form-control" readonly="readonly"/>
									</div>
									<div class="col-xs-4">
										<a href="javascript:void(0);" onclick="showSave(this);" class="editBtn">修改</a>
										<button type="button" class="btn btn-sm btn-outline btn-success hidden" onclick="saveName(this,'mobile')">保存</button>
										<button type="button" class="btn btn-sm btn-outline btn-default hidden" onclick="hideBtns(this);">取消</button>
									</div>
								</div>
								<div class="form-group clear">
									<label for="" class="control-label col-sm-1">密码</label>
									<div class="col-sm-6 inpuDiv">
										<input type="password" id="password" readonly="readonly" class="form-control"/>
									</div>
									<div class="col-xs-4">
										<a href="#myModal" data-toggle="modal">密码修改</a>
									</div>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
		<!--footer-->
		<div class="footer" id="footerA"> </div>
		<!--修改密码-->
		<div class="modal fade " tabindex="-1" role="dialog" id="myModal">
			<div class="modal-dialog modal-lg" role="document" style="margin-top: 10%;">
				<div class="modal-content">
					<div class="modal-header">	
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h4 class="modal-title"><i class="fa fa-pencil"></i> 修改密码</h4>
					</div>
					<div class="modal-body">
						<!--错误信息展示-->
						<div class="msg-wrap hidden">
							<div class="msg-error col-sm-8 col-sm-offset-3"><b></b><span id="msg_txt"></span></div>
						</div>
						<form action="" class="form-horizontal" id="bootvalite">
							<div class="form-group">
								<label for="" class="col-sm-3 control-label"><span class="redStar">*</span> 原密码:</label>
								<div class="col-sm-8 ">
									<input type="password" name="" class="form-control" id="oldPassword" placeholder="请输入原密码">
								</div>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-3 control-label"><span class="redStar">*</span> 新密码:</label>
								<div class="col-sm-8 ">
									<input type="password" name="" class="form-control" id="newPassword" placeholder="请输入新密码">
								</div>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-3 control-label"><span class="redStar">*</span> 确认密码:</label>
								<div class="col-sm-8 ">
									<input type="password" name="" class="form-control" id="newPassword1" placeholder="请再次输入新密码">
								</div>
							</div>
						</form>
					</div>
					<div class="modal-footer">
						<a href="#" class="btn btn-primary btn-sm" onclick="savePwd()">保存</a>
						<button type="button" class="btn btn-default btn-sm" data-dismiss="modal">关闭</button>
					</div>
				</div>
				<!-- /.modal-content -->
			</div>
			<!-- /.modal-dialog -->
		</div>
		<script type="text/javascript">
			var info = {
				id: -1,
				realname: '',
				username: '',
				unit: '',
				position: '',
				mobile: '',
				password: '',
				userType: -1
			}
			$(document).ready(function(){
				if($.cookie('Authorization')===null || localStorage.getItem('realname') === null) {
					showErr("您处于未登录状态，请先登录", '1000000');
					return
				}
				$('#user_span').text(localStorage.getItem('realname') )

				loadInfo()
			})

			// 加载个人信息
			function loadInfo() {
				var userId = localStorage.getItem('userId')
				$.ajax({
					url: service_url + '/a/zkUser/form?id='+userId +'&token=' + $.cookie('Authorization'),
					type: 'GET',
					xhrFields: {
						withCredentials: true
					},
					crossDomain: true,
					contentType: 'application/json',
					dataType: 'jsonp',
					jsonpCallback:"success_jsonpCallback",  
					processData: false, // 告诉jQuery不要去处理发送的数据
					success: function(data) {
						if (data.status === '00') {
							var data = JSON.parse(data.data)
							info.id = data.id
							info.realname = data.realname
							info.username = data.username
							info.unit = data.unit
							info.position = data.position
							info.mobile = data.mobile
							info.password = data.password
							info.userType = data.userType || 0
							$('#realname').val(data.realname)
							$('#username').val(data.username)
							$('#unit').val(data.unit)
							$('#position').val(data.position)
							$('#mobile').val(data.mobile)
							$('#password').val(data.password)
						} else {
							showErr(data.msg)
						}
					},
					error: function(XMLHttpRequest, textStatus, errorThrown) {
						console.log(XMLHttpRequest, textStatus, errorThrown)
					}
				})

			}
			/*显示保存按钮*/
			function showSave(target){
				$(target).nextAll().removeClass("hidden");
				$(target).addClass("hidden");
				$(target).parent().prev().find("input").removeAttr("readonly");
				$(target).parent().prev().find("input").addClass("hasBorder");
			}
			/*显示修改按钮*/
			function hideBtns(target){
				$(target).parent().find("button").addClass("hidden");
				$(target).parent().prev().find("input").attr("readonly","readonly");
				$(target).parent().prev().find("input").removeClass("hasBorder");
				var showVal=$(target).parent().prev().find("input").attr("data-default");
				$(target).parent().prev().find("input").val(showVal);
				$(target).siblings(".editBtn").removeClass("hidden");
			}
			
			function saveName(target,name){
				var value = $("#"+name).val();
				if(name == 'mobile'){
					var reg=/^1[3|4|5|7|8|9][0-9]\d{4,8}$/;
					if(!reg.test(value)){
						top.alert("手机号不正确",{type:'warning'});
						return false;
					}
				}
				if(value == '' || value == null){
					top.alert("不能为空",{type:'warning'});
				}else{
					info[name] = value
					var paramStr = 'id='+info.id+'&'+ name + '=' + encodeURIComponent(value) +'&token=' + $.cookie('Authorization')
					$.ajax({
						url: service_url + '/a/zkUser/zkUserinfoEdit?'+paramStr,
						type: 'GET',
						xhrFields: {
							withCredentials: true
						},
						crossDomain: true,
						contentType: 'application/json',
						dataType: 'jsonp',
						jsonpCallback:"success_jsonpCallback",  
						processData: false, // 告诉jQuery不要去处理发送的数据
						success: function(data) {
							if (data.status === '00') {
								hideBtns(target)
								loadInfo()
							} else {
								showErr(data.msg)
							}
						},
						error: function(XMLHttpRequest, textStatus, errorThrown) {
							console.log(XMLHttpRequest, textStatus, errorThrown)
						}
					})
				}
			}

			function savePwd() {
				var newPassword = $('#newPassword').val()
				var newPassword1 = $('#newPassword1').val()
				var oldPassword = $('#oldPassword').val()

				if (newPassword == '' || oldPassword == '' || newPassword1 == '') {
					showErr('信息不能为空')
				} else {
					if (newPassword !== newPassword1) {
						showErr('两次输入密码不同')
					} else {
						var paramStr = 'id='+info.id+'&password='+oldPassword+'&newPassword='+newPassword+'&token=' + $.cookie('Authorization')
						$.ajax({
						url: service_url + '/a/zkUser/zkUserinfoEdit?'+paramStr,
						type: 'GET',
						xhrFields: {
							withCredentials: true
						},
						crossDomain: true,
						contentType: 'application/json',
						dataType: 'jsonp',
						jsonpCallback:"success_jsonpCallback",  
						processData: false, // 告诉jQuery不要去处理发送的数据
						success: function(data) {
							if (data.status === '00') {
								top.alert("修改密码成功",'','',{type: 'success'})
								$('#newPassword').val('')
								$('#newPassword1').val('')
								$('#oldPassword').val('')
								$('#myModal').modal('hide')
								loadInfo()
							} else {
								showErr(data.msg)
							}
						},
						error: function(XMLHttpRequest, textStatus, errorThrown) {
							console.log(XMLHttpRequest, textStatus, errorThrown)
						}
					})
					}
				}
			}
		</script>
	</body>

</html>